<?php

include_once BONE_ROOT.DS.APP_DIR.DS.'templates'.DS.'content'.DS.'content.php';

class template_listing extends template_content
{

	protected function head()
	{
	$frontpage_id = 0;
	$content_list = $this->get('content_list');
	foreach($content_list as $content)
	{
		if($content->frontpage==1)
		{
			$frontpage_id = $content->id;
			break;
		}
	}
	?>
	<link type="text/css" rel="stylesheet" href="templates/content/css/listing.css">
	<script type="text/javascript" language="javascript" src="templates/content/js/listing.js"></script>
	<script type="text/javascript" language="javascript">var g_iFrontpageID = <?php echo $frontpage_id; ?>;</script>
	<?php
	}

	protected function center()
	{
		
		$category_id = $this->get('category_id');
		$content_list = $this->get('content_list');
		$category_list = $this->get('category_list');
		$pagination = $this->get('pagination');
		
		$this->toolbar();
		?>

<div class="box">
	<div class="box-tl"><div class="box-tr"><div class="box-tm"></div></div></div>	
	<div class="box-m">

		<h3 class="title"><?php echo $this->get_title(); ?></h3>
		
		<div class="info">
		选择分类: 
		<select onchange="javascript:selectCategory(this.options[this.selectedIndex].value)">
		<?php 
		echo '<option value="-1"> - 所有文章 - </option>';
		echo '<option value="0"';
		if(0 == $category_id) echo ' selected';
		echo '>- 未分类文章 -</option>';
		foreach($category_list as $category)
		{
			echo '<option value="'.$category->id.'"';
			if($category->id == $category_id) echo ' selected';
			echo '>';
			if($category->level) echo str_repeat('&nbsp; ', $category->level);
			echo '- '.$category->name.' -</option>';
		}
		?>
		</select>
		</div>
		<table class="list-table">

		<thead>
		<tr>
			<th width="30">#</th><th>标题</th><th width="120">所属分类</th><th width="120">作者</th><th width="120">发布时间</th><th width="60">点击量</th><th width="60">设为首页</th><th width="40">编辑</th><th width="40">删除</th>
		</tr>
		</thead>

		<tbody>
		<?php 
		if(count($content_list))
		{
			foreach($content_list as $content)
			{
				$category_name = '未分类';
				if($content->category_id )
				{
					$category = $category_list[$content->category_id];
					$category_name = $category->name;
				}
			?>
			<tr onMouseOver="this.className='row-on'" onMouseOut="this.className='row-off'">
			<td align="center"><?php echo $content->id; ?></td>
			<td><?php echo $content->title; ?></td>
			<td align="center"><?php echo $category_name; ?></td>
			<td align="center"><?php echo $content->created_by_name; ?></td>
			<td align="center"><?php echo date('Y-m-d H:i',$content->created_time); ?></td>
			<td align="center"><?php echo $content->hits; ?></td>
			<td align="center">
				<a href="javascript:;" onclick="javascript:setFrontpage(<?php echo $content->id; ?>)" class="frontpage-<?php echo $content->frontpage; ?>" id="frontpage-<?php echo $content->id; ?>"></a>
			</td>
			<td align="center">
				<a href="./?controller=content&task=edit&content_id=<?php echo $content->id; ?>" class="edit" title="编辑"></a>
			</td>
			<td align="center">
				<a href="./?controller=content&task=delete&content_id=<?php echo $content->id; ?>" class="delete" title="删除"></a>
			</td>
			</tr>
			<?php
			}
		}
		else
		{
		?>
		<tr>
			<td colspan="9">没有记录</td>
		</tr>
		<?php
		}
		?>
		</tbody>
		
		<tfoot>
		<tr>
			<td colspan="9"><?php $this->pagination(); ?></td>
		</tr>
		</tfoot>
		</table>

	</div>
	<div class="box-bl"><div class="box-br"><div class="box-bm"></div></div></div>
</div>
		

		<?php
		
	}	

}
?>